package omm.domain.evolutiongraph;

import java.util.List;

import org.joda.time.DateTime;

import omm.domain.CommissionStrategy;
import omm.domain.Quotation;
import omm.domain.enums.Commission;

public class EvolutionGraphicFactory {

	public EvolutionGraphic createEvolutionGraphic(List<Quotation> quotations,
			Period periodState, Commission commissionState, Unit unitState, DateTime end) {

		PeriodStrategy periodStrategy = null;
		UnitStrategy unitStrategy = null;
		CommissionStrategy commisionStrategy = new CommissionStrategy(commissionState);

		//TODO: Ver de desharcodear el ancho del grafico
		switch (periodState) {
		case LAST_CLOSED_MONTH_BY_WEEK:
			periodStrategy = new LastClosedMonthPeriodStrategy(400,end);break;
		case CALENDAR_ANUAL_BY_MONTH:
			periodStrategy = new CalendarAnualByMonthPeriodStrategy(400,end);break;
		case ANUAL_BY_MONTH:
			periodStrategy = new AnualByMonthPeriodStrategy(400,end);break;
		}
		switch (unitState) {
		case THOUSANDS://Comisiones de las cotizaciones
			unitStrategy = new ThousandsUnitStrategy();break;
		case QUANTITY://Cantidad de clientes
			unitStrategy = new ClientsQuantityUnitStrategy();break; 
		case QUOT_QUANTITY://Cantidad de cotizaciones
			unitStrategy = new QuotationQuantityUnitStrategy();break;
		}

		return new EvolutionGraphic(quotations, periodStrategy,
				commisionStrategy, unitStrategy);
	}

	/**
	 * 
	 * Enums
	 * 
	 */
	public enum Period {
		LAST_CLOSED_MONTH_BY_WEEK(1), CALENDAR_ANUAL_BY_MONTH(2), ANUAL_BY_MONTH(3);

		private int code;

		Period(int code) {
			this.code = code;
		}

		int getCode() {
			return code;
		}

		public static Period fromCode(Integer code) {
			if (code != null) {
				for (Period b : Period.values()) {
					if (code == b.getCode()) {
						return b;
					}
				}
			}
			return null;
		}

	}

	public enum Unit {
		THOUSANDS(1), QUANTITY(2), QUOT_QUANTITY(3);

		private int code;

		Unit(int code) {
			this.code = code;
		}

		int getCode() {
			return code;
		}

		public static Unit fromCode(Integer code) {
			if (code != null) {
				for (Unit b : Unit.values()) {
					if (code == b.getCode()) {
						return b;
					}
				}
			}
			return null;
		}
	}

	
}
